﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - Book" 
*/ 

component 
	displayname="public.service.db.senate.sequence.Book" 
	output=false 
	accessors=true 
	{

	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		var sql = queryObj = "";
		var nextID = "1" & numberFormat(1, "0____");

		sql = "	SELECT
					b.bid
				FROM
					t_book b
				WHERE
					b.bid LIKE '1_____'
				ORDER BY
					b.bid DESC";

		queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		rs_check = queryObj.execute(sql = sql).getResult();
		/* 
			主键生成规则 CHAR(6)
			
			1起头 5位为流水号 本序列代码代表本、专科教材系列
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = "1" & numberFormat((right(rs_check.bid, 5) + 1), "0____");
			
		}

		return nextID;
	}

}

</cfscript>